package org.example.AI;

/**
 * @author: 默苍璃
 * @date: 2024-07-18 10:53
 */
// 非终结符表达式：除法表达式
public class DivideExpression implements Expression {
    private Expression left;
    private Expression right;

    public DivideExpression(Expression left, Expression right) {
        this.left = left;
        this.right = right;
    }

    @Override
    public int interpret(Context context) {
        int divisor = right.interpret(context);
        if (divisor != 0) {
            return left.interpret(context) / divisor;
        }
        throw new ArithmeticException("除数不能为零！");
    }
}